package com.uplift.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Const {

	private final Logger logger = LogManager.getLogger(Const.class);

	/** HttpSession中用户信息的Key值 */
	public static String SESSION_USER = "session_user";

	public static String REQUEST_USER = "request_user";
	
	public static String JWT_SECRET = "upliftserv";
	
	public static int JWT_EXPIRES_3YEAR = 3;
	
	/** 上传文件存储的目录 */
	public static String DIR_UPLOAD_BASE = "/home/upload/";

	/** 导出收益明细模版 */
	public static String EXCEL_EARNING_TEMPLETE = "/export/EARNING_TEMPLATE";

	public static String FILE_HOST_URL = "";
	
	/** 非保护地址 */
	public static List<String> UNPROTECT_URL = new ArrayList<>();
	
	/** 发件人 */
	public static String MAIL_SENDER = "";
	
	@Value("${dir.upload.base}")
	public void setUploadDir(String dir) {
		DIR_UPLOAD_BASE = dir;
		logger.info("【系统】上传文件存储目录：" + dir);
	}

	@Value("${url.unprotect}")
	public void setUnprotectUrl(String url) {
		String[] unprotectUrlArr = StringUtils.split(url, ",");
		if (unprotectUrlArr != null) {
			UNPROTECT_URL = Arrays.asList(unprotectUrlArr);
		}
		logger.info("【系统】加载不受保护地址：" + UNPROTECT_URL.size() + "个");
	}
	
	@Value("${mail.sender}")
	public void setMailSender(String mailSender) {
		MAIL_SENDER = mailSender;
		logger.info("【系统】系统邮件发件人: " + mailSender);
	}

	@Value("${file.host.url}")
	public void setFileHostUrl(String fileHostUrl) {
		FILE_HOST_URL = fileHostUrl;
		logger.info("文件host url地址: " + fileHostUrl);
	}
}
